/**
 * 返回类似于input blob里的file对象
 * 创建一个隐藏<video>标签
 * <video id="tempVideo" controls="controls" style="width:0;height:0;display:inline-block"><source src=""></video>
 * 并将id传入方法
 * @param callback 返回原来的videoInputFile和新的photoFile
 */
function getVideoThumdnailToInputFile(videoplayerElementId, videoInputFile, fileName, callback) {
    var video = document.getElementById(videoplayerElementId);
    video.addEventListener('loadeddata', onLoaded);
    video.setAttribute("src", getUrl(videoInputFile));
    video.load();
    function onLoaded() {
        var canvas = document.createElement('canvas');
        canvas.width = video.videoWidth;
        canvas.height = video.videoHeight;
        canvas.getContext('2d').drawImage(video, 0, 0, canvas.width, canvas.height);
        canvas.toBlob(function (blob) {
            var photoFile = new File([blob], fileName, {type: "image/jpeg", lastModified: Date.now()});
            callback(videoInputFile, photoFile);
        }, 'image/jpeg');
        video.removeEventListener('loadeddata', onLoaded);
    }
}

function getUrl(file) {
    var url = null;
    if (window.createObjectURL != undefined) {
        url = window.createObjectURL(file);
    } else if (window.webkitURL != undefined) {
        url = window.webkitURL.createObjectURL(file);
    } else if (window.URL != undefined) {
        url = window.URL.createObjectURL(file);
    }
    return url;
}


